package com.psp.web.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.web.controller.res.*;
import com.psp.web.controller.res.bean.*;
import com.psp.web.controller.springmvc.req.*;

/**
 * 发票管理-相关接口
 **/
@Controller
@RequestMapping(value = "/psp/invoice", produces = "application/json")
public class SInvoiceController {
	@Autowired
	com.psp.web.controller.InvoiceController invoiceController;

	/**
	 * 发票抬头详情
	 **/
	@RequestMapping("/v1/headerDetail")
	@ResponseBody
	public ObjectResult<RInvoiceHeaderDetailBean> headerDetail(@Validated GetInvoiceHeaderDetailParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RInvoiceHeaderDetailBean> res = new ObjectResult<RInvoiceHeaderDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return invoiceController.headerDetail(param, request, response);
	}

	/**
	 * 发票抬头列表 
	 **/
	@RequestMapping("/v1/headerList")
	@ResponseBody
	public ListResult<RInvoiceHeaderListBean> headerList(@Validated GetInvoiceHeaderListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RInvoiceHeaderListBean> res = new ListResult<RInvoiceHeaderListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return invoiceController.headerList(param, request, response);
	}

	/**
	 * 发票抬头保存
	 **/
	@RequestMapping("/v1/headerSave")
	@ResponseBody
	public BaseResult headerSave(@Validated GetInvoiceHeaderSaveParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return invoiceController.headerSave(param, request, response);
	}

	/**
	 * 发票抬头删除
	 **/
	@RequestMapping("/v1/headerDelete")
	@ResponseBody
	public BaseResult headerDelete(@Validated GetInvoiceHeaderDeleteParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return invoiceController.headerDelete(param, request, response);
	}
}
